package com.rinlink.jbcodec.creator;

import com.alibaba.fastjson.JSONObject;
import com.rinlink.jbcodec.JSONCodec;
import com.rinlink.jbcodec.ObjectToBytesCreatorMap;
import com.rinlink.jbcodec.transform.JSONToBytes;
import com.rinlink.jbcodec.transform.Transform;

/**
 * @author yhyde
 *
 */
public class JSONToBytesCreator extends ObjectToBytesCreator<JSONObject> {


    private ObjectToBytesCreatorMap creatorMap;

    public JSONToBytesCreator(ObjectToBytesCreatorMap creatorMap){
        this.creatorMap = creatorMap;
    }


    @Override
    protected Transform<byte[]> create(JSONObject data, JSONObject attr, JSONObject source) {
        JSONCodec.Scheme scheme = attr.getJSONObject("scheme").toJavaObject(JSONCodec.Scheme.class);
        return new JSONToBytes(data, scheme, creatorMap);
    }

}
